package com.xdcplus.web.controller.qa;


import com.xdcplus.exceptions.domain.ResponseVO;
import com.xdcplus.mom.controller.AbstractController;
import com.xdcplus.web.common.pojo.dto.QaMtrlBatchReportDTO;
import com.xdcplus.web.common.pojo.vo.qa.QaMtrlBatchReportVO;
import com.xdcplus.web.service.qa.QaMtrlBatchReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;

/**
 * 质量结批报告(QaMtrlBatchReport)表服务控制层
 *
 * @author Devin.Sang
 * @since 2024-01-24 11:44:30
 */
@Api(tags = "质量结批报告(QaMtrlBatchReport)") 
@Slf4j
@Validated
@RestController
@AllArgsConstructor
@RequestMapping("qaMtrlBatchReport")
public class QaMtrlBatchReportController extends AbstractController {

    @Autowired
    private QaMtrlBatchReportService qaMtrlBatchReportService;

    @ApiOperation("获取质量结批报告明细")
    @PostMapping(value = "/queryDetail/{reportCode}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO queryDetail(@PathVariable("reportCode") @NotBlank(message = "结批编号不能为空")  String reportCode) {
        return ResponseVO.success(qaMtrlBatchReportService.queryReportDetailByCode(reportCode));
    }

    @ApiOperation("导出质量结批报告明细excel")
    @GetMapping(value = "/exportExcel", produces = MediaType.APPLICATION_JSON_VALUE)
    public void exportExcelDetail(QaMtrlBatchReportDTO qaMtrlBatchReportDTO,
                                  HttpServletResponse response) throws IOException {
        qaMtrlBatchReportService.exportExcelDetail(qaMtrlBatchReportDTO,response);
    }

    @ApiOperation("保存质量结批报告明细")
    @PostMapping(value = "/saveDetail/{reportCode}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveDetail(@PathVariable("reportCode") String reportCode) {
        qaMtrlBatchReportService.saveReportDetailByCode(reportCode);
        return ResponseVO.success();
    }

    @ApiOperation("手动执行质量结批报告明细")
    @PostMapping(value = "/saveDetail/handle", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO saveDetailByHandle() {
        qaMtrlBatchReportService.qaReportUpdateHandle();
        return ResponseVO.success();
    }


    @ApiOperation("手动报告更新平均效率")
    @PostMapping(value = "/saveDetail/updateReta/{reportCode}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseVO updateReta(@PathVariable("reportCode") String reportCode) {
        qaMtrlBatchReportService.updateRetaReportDetailByCode(reportCode);
        return ResponseVO.success();
    }


}
